package org.qs.webservice.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import org.qs.webservice.exception.QSReadException;
import org.qs.webservice.service.BookRecentService;
import org.qs.webservice.service.BookService;
import org.qs.webservice.service.impl.BookRecentServiceImpl;
import org.qs.webservice.util.IReadUtils;
import org.springframework.stereotype.Component;


@Component
@Path("/v{version}/read")
public class ReadLogRestController {
	
	@Resource
	private BookRecentService bookRecentService;
	/**
	 * 上传阅读日志
	 * @param book_id
	 * @param token
	 * @return
	 */
	@POST
    @Path("/log")
	public String addReadLog(@FormParam("param")String param,@HeaderParam("token")String token,@HeaderParam("info-uuid")String device_identifier){
		try {
			param=IReadUtils.preventInjection(param);
			String ret = bookRecentService.addRecents(param,token, device_identifier);
			return ret;
		} catch (Exception e) {
			Map<String,Object> errorJson = new HashMap<String,Object>();
			errorJson.put("param", param);
			QSReadException.printf(e, "获取书籍详情异常",errorJson);
			Map<String,Object> tokenMap =  new HashMap<String,Object>();
			tokenMap.put("code", 403);
			tokenMap.put("reason","服务器错误");
			return IReadUtils.beanToJson(tokenMap);
		}
	}
	
}
